package com.jiecao.news.jiecaonews.util;

import android.content.Context;
import android.content.SharedPreferences;

import com.jiecao.news.jiecaonews.util.constants.Constants;


public class SharedPreferencesUtil {
	// 写入连接state
	public static void writeConnectState(Context context, int connectType) {
		SharedPreferences spn;
		spn = context.getSharedPreferences(Constants.PREFS_NAME,
				Context.MODE_PRIVATE);
		SharedPreferences.Editor editor = spn.edit();
		editor.putInt(Constants.CONNECT_STATE, connectType);
		editor.commit();
	}

	// 阅读连接state
	public static int readConnectState(Context context) {
		SharedPreferences spn;
		spn = context.getSharedPreferences(Constants.PREFS_NAME,
				Context.MODE_PRIVATE);
		return spn.getInt(Constants.CONNECT_STATE, 0);// 获取当前网络状态，默认无网络
	}

	// 写入flush date
	public static void writeFlushDate(Context context, String flushDate) {
		SharedPreferences spn;
		spn = context.getSharedPreferences(Constants.PREFS_NAME,
				Context.MODE_PRIVATE);
		SharedPreferences.Editor editor = spn.edit();
		editor.putString(Constants.FLUSH_TIME, flushDate);
		editor.commit();
	}

	// 阅读连接flush date
	public static String readFlushDate(Context context) {
		SharedPreferences spn;
		spn = context.getSharedPreferences(Constants.PREFS_NAME,
				Context.MODE_PRIVATE);
		return spn.getString(Constants.FLUSH_TIME, "");
	}
	//第一次发开完毕后写入
	public static void writeFirst(Context context,String nowVersion){
		SharedPreferences spn;
		spn =context. getSharedPreferences(Constants.PREFS_NAME, 0);
		SharedPreferences.Editor editor = spn.edit();
		editor.putBoolean(Constants.FIRST_START, false);
		editor.putString(Constants.STOR_VERSION, nowVersion);
		editor.commit();
	}

}
